package com.googlecode.marrowboy.writers;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

/**
 * Contains a {@link ReportWriter} and a {@link PrintStream} to define what to
 * write to where.
 * 
 * @author mjg
 */
public class OutputConfiguration {

    private final ReportWriter reportWriter;
    private final PrintStream printStream;

    private final File outputFile;

    /**
     * Constructor.
     * 
     * @param reportWriter
     *            the {@link ReportWriter}
     * @param outFile
     *            the {@link File}
     */
    public OutputConfiguration(ReportWriter reportWriter, File outFile) {
        try {
            this.reportWriter = reportWriter;
            this.printStream = new PrintStream(outFile);
            this.outputFile = outFile;
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public OutputConfiguration(ReportWriter reportWriter, PrintStream printStream) {
        this.reportWriter = reportWriter;
        this.printStream = printStream;
        this.outputFile = null;
    }

    public String getOutputFileName() {
        if (outputFile == null){
            return "<unknown file>";
        }
        return outputFile.getAbsolutePath();
    }

    /**
     * Getter
     * 
     * @return the {@link ReportWriter}
     */
    public ReportWriter getReportWriter() {
        return reportWriter;
    }

    /**
     * Getter
     * 
     * @return the {@link PrintStream}
     */
    public PrintStream getPrintStream() {
        return printStream;
    }

}
